package com.bstech.CustomControls;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.bstech.Tabelle.Clienti;
import com.bstech.Tabelle.Clienti.Cliente;
import com.bstech.assistance.R;

public class CommesseSelector extends Activity {
	
	private int idCliente;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.selector);
		
		Bundle bundle = this.getIntent().getExtras();
		if(bundle != null)
			if(bundle.containsKey("idCliente"))
				idCliente = bundle.getInt("idCliente");
		
		LoadControls();
	}
	
	private void LoadControls()
	{
		ListView list = (ListView)findViewById(R.id.selector_listview);
		list.setEmptyView(findViewById(R.id.selector_emptyView));
		
		Cliente c = Clienti.Select(idCliente);
		if(c == null) return;
		
		list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1 ,c.GetExtraordinaryJobs()));
		
		list.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
				Bundle b = new Bundle();
				b.putSerializable("selected", (String)arg0.getItemAtPosition(arg2) );
				Intent intent = new Intent();
				intent.putExtras(b);
				setResult(RESULT_OK, intent);
				finish();
			}
		});
	}
}
